<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>材料收料</title>
		<link rel="stylesheet" type="text/css" href="../static/common.css"/>
		<link rel="stylesheet" type="text/css" href="static/css/enter.css"/>
	</head>
	<body>
		<div class="choose" id="choose" v-cloak>
			<h3>材 料 收 料</h3>
			
			<p class="clearfix">
				<label class="fl clearfix">
					 <span class="block fl"> 供货来源：</span>
					<span class="ml20 fl">{{supplierName}}</span>
				</label>
				
				<label class="fl clearfix">
					 <span class="block fl"> 收料员： </span>
					<span class="ml20 fl">{{name}} {{time}}</span>
				</label>
				
			</p>
			<p class="clearfix">
				<label class="fl clearfix">
					 <span class="block fl"> 材料名称： </span>
					<input type="text"  placeholder="材料名称" value="" class="input fl" v-model="obj.productName" />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 过磅单位： </span>
					<select class="fl select" v-model="obj.productWeighUnit">
						<option v-for='val,index in meterings' :value ="val.id">{{val.name}}</option>
					</select>
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 厂家批次： </span>
					<input type="text"  placeholder="ID-2019070101" value="" class="input fl" v-model="obj.factoryNo" />
				</label>
				
				
				
			</p>
			<p class="clearfix">
				<label class="fl clearfix">
					 <span class="block fl"> 规格型号： </span>
					<input type="text"  placeholder="输入规格型号" value="" class="input fl" v-model="obj.productModel" />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 过磅毛重： </span>
					<input type="number"  placeholder="过磅毛重" value="" class="input fl" v-model="obj.productWeighRough" @focus="add" />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 车牌号： </span>
					<input type="text"  placeholder="如：陕A52698" value="" class="input fl" v-model="obj.carNo" />
				</label>
				
				
				<!-- <label class="fl clearfix">
					 <span class="block fl"> 过磅数量： </span>
					<input type="text"  placeholder="毛重 - 皮重 - 扣重" value="" class="input fl" />
				</label> -->
			</p>
			<p class="clearfix">
				
				<label class="fl clearfix">
					 <span class="block fl"> 计量单位： </span>
					<select class="fl select" v-model="obj.productUnit">
						<option v-for='val,index in meterings' :value ="val.id">{{val.name}}</option>
					</select>
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 过磅扣重： </span>
					<input type="number"  placeholder="请输入过磅扣重" value="" class="input fl" v-model="obj.productWeightDeduct" @focus="add" />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 批次： </span>
					<input type="text"  placeholder="自定义批次" value="" class="input fl" v-model="obj.customNo" />
				</label>
			</p>
			
			<p class="clearfix">
				<label class="fl clearfix">
					 <span class="block fl"> 数量： </span>
					<input type="number"  placeholder="请输入数量" value="" class="input fl" v-model="obj.productQuantity" />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 过磅皮重： </span>
					<input type="number"  placeholder="请输入过磅皮重" value="" class="input fl" v-model="obj.productWeightTare" @focus="add" />
				</label>
				
			</p>
			<p class="clearfix">
				<label class="fl clearfix">
					 <span class="block fl"> 入库时间： </span>
					<input type="text"  placeholder="请选择入库时间" value="" id="time" class="input fl" readonly />
				</label>
				<label class="fl clearfix">
					 <span class="block fl"> 过磅净重： </span>
					<input type="number"  placeholder="请输入过磅净重" value="" class="input fl" v-model="obj.productWeightSuttle" />
				</label>
				
			</p>
			<p class="clearfix last">
				<span class="block fl"> 备注：</span>
				<textarea class="fl" placeholder="请描述材料" v-model="obj.remark">
					
				</textarea>
			</p>
			<em class="err block" style="text-indent: 40px;">{{message}}</em>
			<span class="btnBlue inline-block mt20" style="margin-left: 40px;" @click="addSub">确 认</span>
			<span class="btnBlue inline-block mt20" style="margin-left: 40px;" @click="toUrl">返 回</span>
			
			<h4 class="red mt20" style="text-align: center;">最近收料明细</h4>
			<table class="table tableHover mt20">
				<thead>
					<tr>
						<th width="11%">单号</th>
						<th>供应商</th>
						<th>材料名称</th>
						<th>规格型号</th>
						<th width="6%">计量单位</th>
						<th>数量</th>
						<th width="6%">过磅单位</th>
						<th>过磅净重</th>
						<th>车牌号</th>
						<th>入库时间</th>
						<th>收料员</th>
						<th width="3%">操作</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="val,index in list">
						<td>{{val.orderNo}}</td>
						<td>{{val.supplierName}}</td>
						<td>{{val.productName}}</td>
						<td>{{val.productModel}}</td>
						<td>{{val.productUnitName}}</td>
						<td>{{val.productQuantity}}</td>
						<td>{{val.productWeighUnitName}}</td>
						<td>{{val.productWeightSuttle}}</td>
						<td>{{val.carNo}}</td>
						<td>{{val.receiveDate}}</td>
						<td>{{val.receiverName}}</td>
						<td><span class="listToDetail">打印</span></td>
					</tr>
				</tbody>
			</table>
		</div>
	</body>
</html>
<script src="../static/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/dx.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/laydate/laydate.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/js/vue.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	var Id = DX.getParam('id');
	var endTime = laydate.render({
		elem: '#time',
		// min: $("#starttime").val(), //可选择的最小日期为开始日期
	});
	
	var vm = new Vue({
		el:"#choose",
		mounted:function(){
			this.metering();
			this.getData();
			this.getList();
		},
		data:{
			'message':"",
			'name':'',
			'peopleid':'',
			'time':'',//时间
			'supplierName':'',
			'meterings':[],//计量单位
			'list':[],//最近明细
			'obj':{
				'productUnit':'',//计量单位
				'productWeighUnit':'',//过磅单位
				'productWeighRough':'',//过磅毛重
				'productWeightDeduct':'',//过磅扣重
				'productWeightTare':'',//过磅皮重
				'productWeightSuttle':'',//过磅净重
				'carNo':'',//车牌号
				'factoryNo':'',//厂家批次
				'customNo':'',//自定义批次
				'remark':'',//备注
				'productName':'',//材料名称
				'productModel':'',//规格型号
				'productQuantity':"",//数量
				'receiveDate':'',//入库时间
			}
		},
		methods:{
			metering:function(){//获取计量单位
				var $this = this;
				DX.ajax_method({
					'url':'/materials/supply/product/findProductUnit',
					'callBack':function(res){
						if(res.code == 200){
							console.log(res);
							$this.meterings = res.data;
							$this.obj.productUnit = res.data[0].id;
							$this.obj.productWeighUnit = res.data[0].id;
						}
					}
				})
			},
			getData:function(){//根据id获取数据
				var $this = this;
				DX.ajax_method({
					'url':'/materials/storage/procurement/newProcurementDetail',
					'param':{'supplierId':Id},
					'callBack':function(res){
						if(res.code == 200){
							$this.name = res.data.receiverName;
							$this.time = res.data.receiveDate;
							$this.supplierName = res.data.supplierName;
							$this.peopleid = res.data.receiverId;
							console.log(res);
							// $this.meterings = res.data;
						}
					}
				})
			},
			getList:function(){//获取最近明细
				var $this = this;
				DX.ajax_method({
					'url':'/materials/storage/procurement/findAll',
					'callBack':function(res){
						if(res.code == 200){
							console.log(res);
							$this.list = res.data.list;
						}
					}
				})
			},
			addSub:function(values){
				this.message='';
				var $this =this;
				console.log(this.obj);
				var obj = this.obj;
				obj.receiveDate = $('#time').val();
				obj.supplierId = Id;
				obj.supplierName = this.supplierName;
				obj.receiverName = this.name;
				obj.receiverId = this.peopleid;
				DX.ajax_method({
					'type':'POST',
					'param':obj,
					'change':values.target,
					'url':"/materials/storage/procurement/save",
					'callBack':function(res){
						if(res.code == 200){
							console.log(res);
							$this.getList();
						}else{
							$this.message = res.data;
						}
					}
				})
			},
			add:function(){//计算净重
				if(this.obj.productWeighRough != '' && this.obj.productWeightDeduct != '' && this.obj.productWeightTare){
					this.obj.productWeightSuttle = Number(this.obj.productWeighRough)+Number(this.obj.productWeightDeduct)+Number(this.obj.productWeightTare);
				}
			},
			toUrl:function(){
				window.location.href = 'index.html';
			}
			
		},
		watch:{
			
		}
	})
</script>